package org.jeecg.modules.common.service;

import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.common.entity.CommonClassify;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.common.vo.CommonClassifyVO;
import org.jeecg.modules.common.vo.TreeSelectModel;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Description: 分类管理
 * @Author: jeecg-boot
 * @Date:   2023-08-13
 * @Version: V1.0
 */
public interface ICommonClassifyService extends IService<CommonClassify> {



    /**根节点父ID的值*/
    public static final String ROOT_PID_VALUE = "0";

    /**
     * 存在子节点
     */
    public static final String HAS_CHILD = "1";

    IPage<CommonClassifyVO> page(CommonClassify commonClassify, Integer pageNo, Integer pageSize, HttpServletRequest req);

    /**
     * 添加分类字典
     * @param commonClassify
     */
    void addCommonClassify(CommonClassify commonClassify);

    /**
     * 修改分类字典
     * @param commonClassify
     */
    void updateCommonClassify(CommonClassify commonClassify);

    /**
     * 根据父级编码加载分类字典的数据
     * @param pcode
     * @return
     * @throws JeecgBootException
     */
    public List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException;

    /**
     * 根据pid查询子节点集合
     * @param pid
     * @return
     */
    public List<TreeSelectModel> queryListByPid(String pid);

    /**
     * 根据pid查询子节点集合,支持查询条件
     * @param pid
     * @param condition
     * @return
     */
    public List<TreeSelectModel> queryListByPid(String pid, Map<String,String> condition);


    /**
     * 删除节点时同时删除子节点及修改父级节点
     * @param ids
     */
    void deleteCommonClassify(String ids);

    /**
     * 分类字典控件数据回显[表单页面]
     *
     * @param ids
     * @return
     */
    List<String> loadDictItem(String ids);

    /**
     * 分类字典控件数据回显[表单页面]
     *
     * @param ids
     * @param delNotExist 是否移除不存在的项，设为false如果某个key不存在数据库中，则直接返回key本身
     * @return
     */
    List<String> loadDictItem(String ids, boolean delNotExist);

    Result<IPage<CommonClassify>> queryPageList(CommonClassify sysCategory,
                                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                HttpServletRequest req);

    Result<List<CommonClassify>> queryPageList(CommonClassify sysCategory, HttpServletRequest req);

    Result<CommonClassify> add(@RequestBody CommonClassify sysCategory);

    Result<CommonClassify> edit(@RequestBody CommonClassify sysCategory);

    Result<CommonClassify> delete(@RequestParam(name = "id", required = true) String id);

    Result<CommonClassify> deleteBatch(@RequestParam(name = "ids", required = true) String ids);

    Result<CommonClassify> queryById(@RequestParam(name = "id", required = true) String id);

    ModelAndView exportXls(HttpServletRequest request, CommonClassify sysCategory);

    Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException;

    Result<CommonClassify> loadOne(@RequestParam(name = "field") String field, @RequestParam(name = "val") String val);

    Result<List<TreeSelectModel>> loadTreeChildren(@RequestParam(name = "pid") String pid);

    Result<List<TreeSelectModel>> loadTreeRoot(@RequestParam(name = "async") Boolean async, @RequestParam(name = "pcode") String pcode);

    void loadAllCategoryChildren(List<TreeSelectModel> ls);

    Result<List<TreeSelectModel>> loadDict(@RequestParam(name = "pid", required = false) String pid, @RequestParam(name = "condition", required = false) String condition);

    Result<List<DictModel>> loadAllData(@RequestParam(name = "code", required = true) String code);

    Result getChildListBatch(@RequestParam("parentIds") String parentIds);
}
